<?php
/**
  * Formats a string with zero-based placeholders
  * {0}, {1} etc corresponding to an array of arguments
  * Must pass in a string and 1 or more arguments
  */
function string_format($str) {
	// replaces str "Hello {0}, {1}, {0}" with strings, based on
	// index in array
	$numArgs = func_num_args() - 1;
	
	if($numArgs > 0) {
		$arg_list = array_slice(func_get_args(), 1);
		
		// start after $str
		for($i=0; $i < $numArgs; $i++) {
			$str = str_replace("{" . $i . "}", $arg_list[$i], $str);
		}
	}

	return $str;
}
?>